package com.vm.db;

import android.database.Cursor;
import android.database.SQLException;
import android.util.Log;

public class OperationDao {
	@SuppressWarnings("unused")
	private static DBOpenHelper helper = null;
	static String TAG = "OperationDao";

	// SQLiteDatabase db = null;

	public synchronized void insert(String softId, String packageName) {
		try {
			DBOpenHelper.db
					.execSQL(
							"INSERT INTO operation (softId,packageName) VALUES(?, ?)",
							new Object[] { softId, packageName });
		} catch (SQLException e) {
			Log.d(TAG, "insert---" + e.getMessage());
		}
	}

	public synchronized void deleteOne(String packageName) {
		try {
			DBOpenHelper.db.execSQL(
					"delete from operation where packageName=?",
					new Object[] { packageName });
		} catch (SQLException e) {
			Log.d(TAG, "insert---" + e.getMessage());
		}
	}

	public synchronized void deleteAll() {
		try {
			DBOpenHelper.db.execSQL("delete from operation");
		} catch (SQLException e) {
			Log.d(TAG, "insert---" + e.getMessage());
		}
	}

	public synchronized int query(String packageName) {
		Cursor c = null;
		int result = 0;
		try {
			c = DBOpenHelper.db.rawQuery(
					"SELECT * from operation WHERE packageName=?",
					new String[] { packageName });
			if (c.moveToNext()) {
				result = 1;
			}
		} catch (Exception e) {
			Log.d(TAG, "query---" + e.getMessage());
		} finally {
			if (c != null) {
				c.close();
			}
		}
		return result;
	}

}
